<template>
	<view class="container">
		<view class="header-wrap">
			<text class="title">记录列表</text>
			<view class="filter" @click="onOpenSearch()">
				<uni-icons type="settings" size="24"></uni-icons>
				<text>筛选</text>
			</view>
		</view>

		<view class="content-wrap">
			<view class="item" v-for="item in useDataResult.dataList">
				<text>活动编号：{{ item.activityNo }}</text>
				<view class="line"></view>
				<text class="title">{{ item.activityName }}</text>
				<text class="info">奖品名称：{{ item.goodsName }}</text>
				<text class="info">核销机构：{{ item.agentName }}</text>
				<text class="info">核销时间：{{ item.writeTime }}</text>
				<text class="info">活动时间：{{ item.startTime }}~{{ item.endTime }}</text>
				<view class="line"></view>
				<text class="title">领用人信息</text>
				<view class="number">
					<text class="info">姓名：{{ item.nickName }}</text>
					<view class="detail" @click="onOpenInfo(item)">查看详情</view>
				</view>
				<text class="info">手机号：{{ item.phone }}</text>
			</view>
		</view>

		<!-- 普通弹窗 -->
		<uni-popup ref="searchPopup" type="top">
			<view class="popup-content">
				<view class="item">
					<text>活动编号</text>
					<input class="input" placeholder-style="color:#BBBBBB" placeholder="请输入活动编号" v-model="vdata.queryParams.activityNo" />
				</view>
				<view class="item">
					<text>活动名称</text>
					<input class="input" placeholder-style="color:#BBBBBB" placeholder="请输入活动名称" v-model="vdata.queryParams.activityName" />
				</view>
				<view class="item">
					<text>核销时间</text>
					<view class="time" @click="onOpenDate()">
						<text :style="vdata.queryParams.writeTime?'color:#333':'color:#BBBBBB'">{{vdata.queryParams.writeTime?vdata.queryParams.writeTime:'核销时间'}}</text>
						<uni-icons type="down" color="#A0A9C0" size="20"></uni-icons>
					</view>
				</view>
				<view class="bottom-wrap">
					<text class="reset" @click="onReset">重置</text>
					<text class="query" @click="onQuery">查询</text>
				</view>
			</view>
		</uni-popup>

		<!-- 详情弹窗 -->
		<uni-popup ref="infoPopup" type="bottom">
			<view class="popup-info">
				<text class="title">领用详情</text>
				<uni-icons type="closeempty" size="24" color="darkgray" class="close" @click="onCloseInfo()"></uni-icons>

				<view class="content">
					<view class="item">
						<text>领用人姓名</text>
						<text>{{ vdata.currentRecord.nickName }}</text>
					</view>
					<view class="item">
						<text>领用人手机号</text>
						<text>{{ vdata.currentRecord.phone }}</text>
					</view>
					<!-- <view class="item">
						<text>领用人OPENID</text>
						<text>66hhl33456g</text>
					</view> -->
					<view class="line"></view>
					<view class="item">
						<text>奖品图片</text>
						<image :src="vdata.currentRecord.goodsImgs"></image>
					</view>
					<view class="item">
						<text>中奖时间</text>
						<text>{{ vdata.currentRecord.createdAt }}</text>
					</view>
					<view class="line"></view>
					<view class="item">
						<text>核销状态</text>
						<text>已核销</text>
					</view>
					<view class="item">
						<text>核销时间</text>
						<text>{{ vdata.currentRecord.writeTime }}</text>
					</view>
					<view class="item">
						<text>核销机构</text>
						<text>{{ vdata.currentRecord.agentName }}</text>
					</view>
				</view>
				<text class="bottom-wrap" @click="onCloseInfo()">
					确定
				</text>
			</view>
		</uni-popup>

		<!-- 日历 -->
		<uni-calendar ref="calendarRef" :insert="false" @confirm="onConfirmDate" />
	</view>
</template>

<script setup>
	import { reactive, ref, } from 'vue'
	import { $destoryAwardRecord } from '@/http/marketing/apiMarketing.js'
	import useGetList from '@/hooks/useGetList.js'

	const { useDataResult, getList } = useGetList($destoryAwardRecord, data => data, { })

	// 搜索弹窗
	const searchPopup = ref();

	// 搜索弹窗
	const calendarRef = ref();

	// 领取详情弹窗
	const infoPopup = ref();


	const vdata = reactive({
		queryParams: {
			activityNo: '',
			activityName: '',
			writeTime: '',
		},
		currentRecord: {}, // 当前记录
	})

	/**
	 * 打开搜索弹窗
	 */
	const onOpenSearch = () => {
		searchPopup.value.open();

	}
	/**
	 * 筛选
	 */
	const onQuery = () => {
		getList(vdata.queryParams)
		onCloseSearch()
	}
	/**
	 * 重置
	 */
	const onReset = () => {
		vdata.queryParams = {
			activityNo: '',
			activityName: '',
			writeTime: '',
		}
	}

	/**
	 * 关闭搜索弹窗
	 */
	const onCloseSearch = () => {
		searchPopup.value.close();
	}

	/**
	 * 打开领取详情弹窗
	 */
	const onOpenInfo = (record) => {
		vdata.currentRecord = record
		infoPopup.value.open();
	}

	/**
	 * 关闭领取详情弹窗
	 */
	const onCloseInfo = () => {
		infoPopup.value.close();
	}

	/**
	 * 打开日历
	 */
	const onOpenDate = () => {
		calendarRef.value.open();
	}

	/**
	 * 日期选择
	 */
	const onConfirmDate = (result) => {
		vdata.queryParams.writeTime = result.fulldate
	}


	const contentList = [{
		no: "LKLDLKWDL1001",
		title: '周一会员日：爆款买2送1',
		time: '2024.03.04～2024',
		no1: 210,
		no2: 1000,
		price: 123
	}, {
		no: "LKLDLKWDL1001",
		title: '周一会员日：爆款买2送1',
		no1: 210,
		no2: 1000,
		time: '2024.03.04～2024',
		price: 123
	}, {
		no: "LKLDLKWDL1001",
		title: '周一会员日：爆款买2送1',
		no1: 210,
		no2: 1000,
		time: '2024.03.04～2024',
		price: 123
	}]
</script>

<style lang="less">
	@page-backgroud: #F6F7FC; //页面背景色

	page {
		background: @page-backgroud;
	}

	.container {
		min-height: 100vh;
		padding: 30rpx 20rpx 30rpx 20rpx;
		box-sizing: border-box;
		overflow: hidden;

		.header-wrap {
			width: 100%;
			position: fixed;
			height: 120rpx;
			top: 0;
			left: 0;
			display: flex;
			justify-content: space-between;
			align-items: center;
			z-index: 2;
			box-sizing: border-box;
			padding: 0 30rpx;
			background-color: @page-backgroud;

			.title {
				font-weight: bold;
				font-size: 32rpx;
				color: #333333;
				font-style: normal;
				flex-grow: 1;
			}


			.filter {
				display: flex;
				align-items: center;
				border-radius: 40rpx;
				background-color: white;
				padding: 8rpx 20rpx;
				border: 1rpx solid #C8C8C8;

				text {
					font-size: 26rpx;
					color: black;
					letter-spacing: 1px;
					margin-bottom: 2rpx;
				}
			}

		}

		.content-wrap {
			position: relative;
			z-index: 0;
			margin: 120rpx 20rpx 30rpx 20rpx;

			.item {
				box-sizing: border-box;
				padding: 30rpx;
				background: #fff;
				border-radius: 20rpx;
				box-shadow: 0rpx -10rpx 30rpx -30rpx rgba(0, 0, 0, 0.8);
				display: flex;
				flex-direction: column;
				margin-bottom: 30rpx;
				color: black;
				font-size: 26rpx;

				.line {
					height: 1rpx;
					background-color: #E6E6E6;
					margin: 20rpx 0rpx;
				}

				.title {
					font-weight: bold;
					font-size: 32rpx;
					color: #333333;
					margin: 15rpx 0rpx;
				}

				.info {
					margin-bottom: 10rpx;
					color: #999999FF;
				}

				.number {
					display: flex;
					align-items: center;
					justify-content: space-between;
					color: darkgray;


					.detail {
						border: 1rpx solid #C8C8C8;
						border-radius: 35rpx;
						background-color: white;
						padding: 15rpx 30rpx;
						color: #333333;
						box-shadow: 0rpx -10rpx 30rpx -30rpx rgba(0, 0, 0, 0.8);
					}

				}

			}
		}

		.popup-content {
			display: flex;
			flex-direction: column;
			align-items: center;
			padding: 40rpx 30rpx;
			font-size: 26rpx;
			background-color: white;
			border-radius: 0 0 20rpx 20rpx;
			letter-spacing: 1px;
			box-sizing: border-box;
			margin-top: 120rpx;

			.item {
				display: flex;
				flex-direction: column;
				font-size: 28rpx;
				margin-bottom: 30rpx;
				width: 100%;

				.input {
					border-radius: 40rpx;
					padding: 18rpx 30rpx;
					background-color: #F6F7FC;
					margin-top: 20rpx;
					font-size: 30rpx;
				}

				.time {
					border-radius: 40rpx;
					padding: 18rpx 30rpx;
					background-color: #F6F7FC;
					font-size: 30rpx;
					flex-grow: 1;
					display: flex;
					justify-content: space-between;
					color: #BBBBBB;
					margin-top: 20rpx;
				}

			}


			.bottom-wrap {
				display: flex;
				flex-direction: row;
				align-items: center;
				font-size: 30rpx;
				margin-top: 30rpx;
				margin-bottom: 10rpx;
				width: 100%;

				.reset {
					color: black;
					border-radius: 40rpx;
					width: 25%;
					padding: 18rpx 0rpx;
					background-color: #F4F5F5;
					text-align: center;
					margin-right: 30rpx;
				}

				.query {
					color: white;
					border-radius: 40rpx;
					width: 75%;
					padding: 18rpx 0rpx;
					background-color: #24C789;
					margin-top: 30rpx;
					text-align: center;
					margin-bottom: 10rpx;
				}
			}

		}

		.popup-info {
			display: flex;
			flex-direction: column;
			padding: 40rpx 30rpx;
			font-size: 28rpx;
			background-color: white;
			border-radius: 20rpx 20rpx 0 0;
			letter-spacing: 1px;
			box-sizing: border-box;
			position: relative;

			.title {
				font-weight: bold;
				font-size: 32rpx;
				color: #333333;
				margin-bottom: 20rpx;
				text-align: center;
			}

			.close {
				position: fixed;
				right: 0;
				top: 0;
				margin-top: 25rpx;
				margin-right: 25rpx;
			}

			.line {
				height: 1rpx;
				margin: 20rpx 0rpx;
				border-bottom: 1rpx dotted #E6E6E6;
			}

			.item {
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-bottom: 30rpx;

				image {
					width: 280rpx;
					height: 150rpx;
				}
			}

			.content {
				background-color: #F6F7FCFF;
				border-radius: 15rpx;
				padding: 30rpx 30rpx 0 30rpx;
				color: #666666FF;
			}

			.bottom-wrap {
				font-size: 30rpx;
				width: 100%;
				color: white;
				border-radius: 40rpx;
				padding: 20rpx 0rpx;
				background-color: #24C789;
				margin-top: 40rpx;
				text-align: center;
				margin-bottom: 10rpx;
			}

		}

	}
</style>